#include "ground.hpp"

Ground::Ground(){
    for (unsigned int i = 0; i < groundModel.fSets.size(); i++){
        fPoint SV1, SV2, SV3;
        
        // Get Index
        int firstVertexIndex = (groundModel.fSets[i])[0];
        int secondVertexIndex = (groundModel.fSets[i])[1];
        int thirdVertexIndex = (groundModel.fSets[i])[2];

        // Get Value
        SV1.x = (groundModel.vSets[firstVertexIndex])[0];
        SV1.y = (groundModel.vSets[firstVertexIndex])[2];

        SV2.x = (groundModel.vSets[secondVertexIndex])[0];
        SV2.y = (groundModel.vSets[secondVertexIndex])[2];

        SV3.x = (groundModel.vSets[thirdVertexIndex])[0];
        SV3.y = (groundModel.vSets[thirdVertexIndex])[2];

        // Make Triangle
        vector<fPoint> triangle;
        triangle.push_back(SV1);
        triangle.push_back(SV2);
        triangle.push_back(SV3);

        
        // Push Triangle
        if(groundModel.fSets[i][3] == groundModel.mtlMap["ground"] || groundModel.fSets[i][3] == groundModel.mtlMap["start"]){
            groundTriangles.push_back(triangle);
        }
        else if(groundModel.fSets[i][3] == groundModel.mtlMap["park"]){
            parkTriangles.push_back(triangle);
        }
    }
}

void Ground::Draw(){
    groundModel.Draw();
}

bool Ground::pointOnGround(fPoint point){
    for (unsigned int i = 0; i < groundTriangles.size(); i++){
        if(IsPointInTri(point, groundTriangles[i][0], groundTriangles[i][1], groundTriangles[i][2])){
            return true;
        }
    }
    return false;
}

bool Ground::pointOnPark(fPoint point){
    for (unsigned int i = 0; i < parkTriangles.size(); i++){
        if(IsPointInTri(point, parkTriangles[i][0], parkTriangles[i][1], parkTriangles[i][2])){
            return true;
        }
    }
    return false;
}
